#!/bin/sh
# Job yaml can send below ENVIRONMENT VARIABLES to me
# - server_process
# - client_process
# END ENVIRONMENT VARIABLES

echo "clean process start"
if [ "${node_roles}" ==  "server" ] && [ $(ps -ef|grep "${server_process}"|grep -v grep|wc -l) -gt 0 ]; then
	echo "kill server node ${server_process}"
        ps -ef|grep "${server_process}"|grep -v grep|awk '{print $2}'|xargs kill -9
fi

if [ "${node_roles}" ==  "client" ] && [ $(ps -ef|grep "${client_process}"|grep -v grep|wc -l) -gt 0 ]; then
	echo "kill client node ${client_process}"
        ps -ef|grep "${client_process}"|grep -v grep|awk '{print $2}'|xargs kill -9
fi

echo "clean process finished"
